<?php
namespace app\index\controller;
use app\index\model\Users;
use think\Controller;
use think\View;

class User extends Controller{

    public function login(){
        $view = new View();
        return $view->fetch('login');
    }

    public function logincheck(){
        $u = new Users();
        $username = input('post.username');
        $password = input('post.password');
        $result = $u->where([
            'username'=>$username,
            'password'=>$password,
        ])->find();
        if($result){
            session('username',$username);
            session('islogin',1);
            session('userid',$result['userid']);
//            return $this->success('登录成功','index/index/index');
        }else{
            echo "<script>alert('用户名或密码错误');</script>";
            echo "<script>location.href='"."{:url('index/index/login')}"."</script>";
        }

    }

}